package com.example.work3

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class Activity3 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_3)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        //在MainActivity中点击第2个按钮启动第2个二级Activity，第2个二级Activity中输入内容确定后可将内容返回MainActivity并显示返回结果
        val msg = findViewById<EditText>(R.id.input)


        val btn2 = findViewById<Button>(R.id.confirm)
        btn2.setOnClickListener {
            val intent = Intent()
            intent.putExtra("result", msg.text.toString())
            setResult(1, intent)
            finish()
        }

    }
}